﻿using Lmondeil.Crm.EF;
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Atlanchim.Crm.Mui.Rapports
{
    /// <summary>
    /// Interaction logic for PageRapportSocietes.xaml
    /// </summary>
    public partial class PageRapportSocietes : UserControl
    {
        public PageRapportSocietes()
        {
            InitializeComponent();
            _reportViewer.Load += _reportViewer_Load;
        }

        private bool _isReportViewLoaded;

        void _reportViewer_Load(object sender, EventArgs e)
        {
            if (!_isReportViewLoaded)
            {
                using (CrmContext context = new CrmContext())
                {
                    ReportDataSource reportDataSource1 = new ReportDataSource();

                    reportDataSource1.Name = "DataSet_Societes";
                    reportDataSource1.Value = context.Societes.ToList();

                    this._reportViewer.LocalReport.DataSources.Add(reportDataSource1);
                    this._reportViewer.LocalReport.ReportEmbeddedResource = "Atlanchim.Crm.Mui.Rapports.ReportSocietes.rdlc";

                    _reportViewer.RefreshReport();

                    _isReportViewLoaded = true;
                }
            }
        }
    }
}
